package ezonsport.android.ui.stepSystem.goalManage;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
import android.widget.TextView;
import ezonsport.android.R;
import ezonsport.android.application.SystemConstant;

//Not be used currently
public class GoalAdapter extends BaseAdapter {
	private Context mContext;
	private LayoutInflater mListContainer; 
	private List<Map<String, Object>> mListItems;
	private int temp = -1;
	private View mView;
	
	public final class ListItemView{
		public TextView mGoalText;
		public RadioButton mGoalChoice;
	}
	
	public GoalAdapter(Context context, List<Map<String, Object>> listItems){
		mContext = context;
		mListContainer = LayoutInflater.from(context);
		mListItems = listItems;		
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		mListItems.size();
		return 0;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ListItemView listItemView = null;
		if(convertView == null){
			listItemView = new ListItemView();
			convertView = mListContainer.inflate(R.layout.goalsetting_listitem_choice, null);
			listItemView.mGoalText = (TextView)convertView.findViewById(R.id.goalsetting_tx_fixed_goalchoice);
			//listItemView.mGoalChoice = (RadioButton)convertView.findViewById(R.id.goalsetting_radiobutton);	
			convertView.setTag(listItemView);
		}else{
			listItemView = (ListItemView)convertView.getTag();
		}
		mView = convertView;
		listItemView.mGoalText.setText((String)mListItems.get(position).get(SystemConstant.GoalsSetting.GOALTEXT));
		listItemView.mGoalChoice.setId(position);
		listItemView.mGoalChoice.setOnCheckedChangeListener(new OnCheckedChangeListener(){
			
			@Override
			public void onCheckedChanged (CompoundButton buttonView, boolean isChecked){
				if(isChecked){
					if(temp != -1){
						RadioButton button = (RadioButton)mView.findViewById(temp);
						button.setChecked(false);					
					}
					temp = buttonView.getId();				
				}
			}
		});
		return convertView;
	}

}
